package com.jdrx.sw.sewage.api.web;

import com.jdrx.ocp.beans.constans.EDeleteFlag;
import com.jdrx.platform.commons.rest.beans.dto.IdDTO;
import com.jdrx.platform.commons.rest.beans.vo.ResponseVO;
import com.jdrx.platform.commons.rest.factory.ResponseFactory2;
import com.jdrx.sw.sewage.beans.dto.WaterQualityTestAddDTO;
import com.jdrx.sw.sewage.beans.dto.WaterQualityTestQueryDTO;
import com.jdrx.sw.sewage.beans.dto.WaterQualityTestUpdateDTO;
import com.jdrx.sw.sewage.beans.entity.WaterQualityTestPO;
import com.jdrx.sw.sewage.beans.vo.base.PageVO;
import com.jdrx.sw.sewage.service.WaterQualityTestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping(value = "/api/waterQualityTest")
@Api(value = "水质化验报表")
public class WaterQualityTestApi {
    @Autowired
    private WaterQualityTestService waterQualityTestService;

    @ApiOperation(value = "新增水质化验报表")
    @PostMapping(value = "add")
    public ResponseVO<?> add(@RequestBody @Validated WaterQualityTestAddDTO dto) {
        waterQualityTestService.add(dto);
        return ResponseFactory2.ok();
    }

    @ApiOperation(value = "修改水质化验报表")
    @PostMapping(value = "update")
    public ResponseVO<?> update(@RequestBody @Validated WaterQualityTestUpdateDTO dto) {
        waterQualityTestService.update(dto);
        return ResponseFactory2.ok();
    }

    @ApiOperation(value = "删除水质化验报表")
    @PostMapping(value = "delete")
    public ResponseVO<?> delete(@RequestBody @Validated IdDTO<Long> dto) {
        WaterQualityTestUpdateDTO dto2 = new WaterQualityTestUpdateDTO();
        dto2.setId(dto.getId());
        dto2.setDeleteFlag(Integer.valueOf(EDeleteFlag.DELETE.getKey()));
        waterQualityTestService.update(dto2);
        return ResponseFactory2.ok();
    }

    @ApiOperation(value = "水质化验报表分页列表")
    @PostMapping(value = "pageList")
    public ResponseVO<PageVO<WaterQualityTestPO>> pageList(@RequestBody @Validated WaterQualityTestQueryDTO dto) {
        return ResponseFactory2.ok(waterQualityTestService.pageList(dto));
    }

    @ApiOperation(value = "水质化验报表详情")
    @PostMapping(value = "getById")
    public ResponseVO getById(@RequestBody @Valid IdDTO<Long> dto) {
        return ResponseFactory2.ok(waterQualityTestService.getById(dto));
    }
}